// pages/wx_request/wx_request.js
Page({

    /**
     * Page initial data
     */
    data: {
        datalist: [
            {
                title: "Titile1",
                time: "time1",
                url: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQBgdIAKA4W7NvdN7t0jnxBbrFIiDwoWd7Q8g&usqp=CAU"
            },
            {
                title: "Titile2",
                time: "time2",
                url: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQBgdIAKA4W7NvdN7t0jnxBbrFIiDwoWd7Q8g&usqp=CAU"

            },
            {
                title: "Titile3",
                time: "time3",
                url: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQBgdIAKA4W7NvdN7t0jnxBbrFIiDwoWd7Q8g&usqp=CAU"

            }
        ],
        request_data: [

        ],
        number: 1
    },

    // 封装
    getList: function (pagenum = 1) {
        wx.request({
            url: 'https://edu.newsight.cn/wxList.php',
            data: {
                // 只拿 5 条数据
                num: 5,
                page: pagenum
            },
            success:res=>{
                console.log(res.data)
                this.setData({
                    request_data: res.data
                })
            }
        })
    },

    nextPage: function (params) {
        this.data.number++;
        this.getList(this.data.number);
    },

    /**
     * Lifecycle function--Called when page load
     */
    onLoad: function (options) {
        // wx.request({
        //   url: 'https://edu.newsight.cn/wxList.php',
        //   data: {
        //       // 只拿 5 条数据
        //       num: 5,
        //       page: 2
        //   },
        //   success:res=>{
        //       console.log(res.data)
        //       this.setData({
        //           request_data: res.data
        //       })
        //   }
        // })
        
        // 调用函数
        this.getList();
    },

    /**
     * Lifecycle function--Called when page is initially rendered
     */
    onReady: function () {

    },

    /**
     * Lifecycle function--Called when page show
     */
    onShow: function () {

    },

    /**
     * Lifecycle function--Called when page hide
     */
    onHide: function () {

    },

    /**
     * Lifecycle function--Called when page unload
     */
    onUnload: function () {

    },

    /**
     * Page event handler function--Called when user drop down
     */
    onPullDownRefresh: function () {

    },

    /**
     * Called when page reach bottom
     */
    onReachBottom: function () {

    },

    /**
     * Called when user click on the top right corner to share
     */
    onShareAppMessage: function () {

    }
})